package com.zerosky.crm.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.zerosky.crm.dao.BranchDAO;
import com.zerosky.crm.po.Branch;
import com.zerosky.crm.service.BranchService;
import com.zerosky.crm.util.PageInfo;

@Service(value="branchService")
public class BranchServiceImpl implements BranchService {
	@Autowired
	private BranchDAO branchDao;

	@Transactional(propagation = Propagation.NOT_SUPPORTED) // 不开启事务
	public List<Branch> getBranchAllList(Map map) {
		return branchDao.getBranchAllList(map);
	}

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED) // 不开启事务
	public PageInfo<Branch> getBranchPageInfoList(Map map) {
		int begin = (((int) map.get("page") - 1) * (int) map.get("limit"));
		int pageSize = (int) map.get("limit");
		PageInfo<Branch> page = new PageInfo<Branch>();
		// 写入数据
		map.put("pageNo", begin);
		map.put("pageSize", pageSize);
		List<Branch> list = branchDao.getBranchAllList(map);
		page.setList(list);

		Integer count = branchDao.countBranch(map);// 获取总记录
		page.setPageCount(count);
		return page;
	}

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED) // 不开启事务
	public Branch getBranchById(String branchId) {
		return branchDao.getBranchById(branchId);
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED) // 创建一个事务，如果有则加入事务
	public void addBranch(Branch branch) {
		branchDao.addBranch(branch);
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED) // 创建一个事务，如果有则加入事务
	public void updateBranch(Branch branch) {
		branchDao.updateBranch(branch);
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED) // 创建一个事务，如果有则加入事务
	public void deleteBranchById(String branchId) {
		branchDao.deleteBranchById(branchId);
	}

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED) // 不开启事务
	public List<Branch> getBranchPhoneBookList(Map<String, Object> map) {
		return branchDao.getBranchPhoneBookList(map);
	}

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED) // 不开启事务
	public List<Branch> getBranchByFkDeptId(String deptId) {
		return branchDao.getBranchByFkDeptId(deptId);
	}

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED) // 不开启事务
	public List<Branch> getBranchByBranchId(String id) {
		return branchDao.getBranchByBranchId(id);
	}

}
